﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Vortex.IO {

	/// <summary>
	/// Implements IResourceProvider interface for File System
	/// </summary>
	class FileSystemResourceProvider : IResourceProvider {
		private FileInfo _fileInfo;

		/// <summary>
		/// Check is there are file with specified file name on file system
		/// </summary>
		/// <param name="filename">The filename.</param>
		/// <returns></returns>
		public static bool Exists(string filename) {
			return new FileInfo(filename).Exists;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="FileSystemResourceProvider"/> class.
		/// </summary>
		/// <param name="filename">The filename.</param>
		public FileSystemResourceProvider(string filename) {
			_fileInfo = new FileInfo(filename);

			if (!_fileInfo.Exists) {
				throw new FileNotFoundException("No resource file found on file system", filename);
			}
		}

		#region IResourceProvider Members

		/// <summary>
		/// Opens the reading stream for resource.
		/// </summary>
		/// <returns></returns>
		public Stream OpenStream() {
			return _fileInfo.OpenRead();
		}

		#endregion
	}
}
